﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace INSTA.BankApplication.Engine
{
    /// <summary>
    /// Base class for all Persons
    /// </summary>
    public class Person
    {
        private string      _name;
        private string      _firstName;
        private int         _yearOfBirth;

        #region -- Constructeurs --


        /**********************************************************************
         * 
         * Constructor(s)
         * 
         **********************************************************************/


        /// <summary>
        /// Constructor
        /// </summary>
        public Person()
            : this(string.Empty, string.Empty, 0)
        { }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="name">The Name</param>
        public Person(string name)
            : this(name, string.Empty, 0)
        { }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="name">the name</param>
        /// <param name="firstName">the first name</param>
        public Person(string name, string firstName)
            : this(name, firstName, 0)
        { }


        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="name">the name</param>
        /// <param name="firstName">the first name</param>
        /// <param name="yearOfBirth">the year of birth</param>
        public Person(string name, string firstName, int yearOfBirth)
        {
            Name = name;
            FirstName = firstName;
            YearOfBirth = yearOfBirth;
        }


        #endregion

        #region -- Properties --

        /**********************************************************************
         * 
         * Properties
         * 
         **********************************************************************/



        /// <summary>
        /// Person's Name.
        /// </summary>
        public string Name
        {
            get { return _name; }
            set { _name = value.ToUpper(); }
        }

        /// <summary>
        /// Person's First Name.
        /// </summary>
        public string FirstName
        {
            get { return _firstName; }
            set
            {
                if (value.Length > 10)
                {
                    value = value.Substring(0, 10);
                }

                _firstName = value;
            }
        }

        /// <summary>
        /// <see cref="Person"/> Year of birth.
        /// </summary>
        public int YearOfBirth
        {
            get { return _yearOfBirth; }
            set
            {
                int currentYear = DateTime.Now.Year;

                if (value < currentYear - 100 || value > currentYear)
                {
                    _yearOfBirth = -1;
                }
                else
                {
                    _yearOfBirth = value;
                }
            }
        }

        /// <summary>
        /// Gets the <see cref="Person"/>'s Age.
        /// </summary>
        public int Age
        {
            get
            {
                int currentYear = DateTime.Now.Year;
                int result = _yearOfBirth == -1 ? -1 : currentYear - _yearOfBirth;

                return result;
            }
        }

        #endregion

    }
}
